//生产管理系统/数据趋势分析/填表
import React, { Component } from "react";
import { connect } from "dva";
import MyIcon from "../../../components/common/MyIcon";
import publicService from "../../../services/PublicService";
import {
    Divider,
    Modal,
    Table,
    Select,
    Card,
    DatePicker,
    Menu,
    Dropdown,
    Button,
    Icon,
    Pagination
} from "antd";
import style from "./Fill.less";
import moment from "moment";
import {
    reportformsinquire,
    reportformsadd,
    statementDelete,
    disposeQuery,
    disposeDelete,
    disposeAdd,
    repairQuery,
    repairDelete,
    repairAdd
} from "../../../services/redmoe";
import request from "../../../utils/request";
import CollectionCreateForm from "./modal/Addmodal";
import Editmodal from "./modal/Editmodal";
import Checkmodal from "./modal/Checkmodal";

function handleChange(value) {
    console.log(`selected ${value}`);
}

const confirm = Modal.confirm;

const { MonthPicker, RangePicker } = DatePicker;

//下拉选择器套件
const Option = Select.Option;


class Fill extends Component {
    state = {
        tableLoading: false,
        RangePicker: null,
        selectedRowKeys: [],
        editState: 0,
        pg: "",
        repairWidth: null,
        row1: {},
        row: {},
        btn: "",
        endDate: "",
        startDate: "",
        loading: false,
        visible: false,
        visible1: false,
        visible2: false,
        page: 1,
        text1: "能源消耗统计表",
        rows: 10,
        text: "能源消耗统计表",
        data: [],
        columns: []
    };

    //日期选择事件
    RangePicker = (data, datastring) => {
        console.log(data);
        console.log(datastring[0]);
        this.setState({
            startDate: datastring[0],
            endDate: datastring[1],
            RangePicker: [data[0], data[1]]
        });
    };

    //弹出框套件
    showModal = () => {
        //新增
        this.setState({
            visible: true,
            btn: "新增"
        });
    };
    showModal1 = () => {
        //编辑

        if (this.state.row.length == 1) {
            var a1 = this.state.row[0];
            if (this.state.text == "能源消耗统计表") {
                request(
                    `/hh-management-web/gnhj/energyconsumption/getEnergyConsumption?id=${
                        a1.id
                    }`
                ).then(data => {
                    console.log(data);
                    this.setState({
                        visible1: true,
                        btn: "编辑",
                        row1: data.data.ret
                    });
                });
            }

            if (this.state.text == "土壤处理量统计表") {
                request(
                    `/hh-management-web/gnhj/soilTreatment/getSoilTreatment?id=${
                        a1.id
                    }`
                ).then(data => {
                    console.log(data);
                    this.setState({
                        visible1: true,
                        btn: "编辑",
                        row1: data.data.ret
                    });
                });
            }

            if (this.state.text == "土壤修复指标汇总表") {
                request(
                    `hh-management-web/gnhj/soilremediation/getSoilRemediation?id=${
                        a1.id
                    }`
                ).then(data => {
                    console.log(data);
                    this.setState({
                        visible1: true,
                        btn: "编辑",
                        row1: data.data.ret
                    });
                });
            }

            console.log(a1);
        }
    };
    showModal2 = () => {
        //查看
        if (this.state.row.length == 1) {
            var a1 = this.state.row[0];

            if (this.state.text == "能源消耗统计表") {
                request(
                    `/hh-management-web/gnhj/energyconsumption/getEnergyConsumption?id=${
                        a1.id
                    }`
                ).then(data => {
                    console.log(data);
                    this.setState({
                        visible2: true,
                        btn: "编辑",
                        row1: data.data.ret
                    });
                });
            }

            if (this.state.text == "土壤处理量统计表") {
                request(
                    `/hh-management-web/gnhj/soilTreatment/getSoilTreatment?id=${
                        a1.id
                    }`
                ).then(data => {
                    console.log(data);
                    this.setState({
                        visible2: true,
                        btn: "编辑",
                        row1: data.data.ret
                    });
                });
            }

            if (this.state.text == "土壤修复指标汇总表") {
                request(
                    `hh-management-web/gnhj/soilremediation/getSoilRemediation?id=${
                        a1.id
                    }`
                ).then(data => {
                    console.log(data);
                    this.setState({
                        visible2: true,
                        btn: "编辑",
                        row1: data.data.ret
                    });
                });
            }
        }
    };

    handleCancel = () => {
        this.setState({ visible: false, visible1: false, visible2: false });
    };
    //获取新增表单中的值 随后请求
    handleCreate = () => {
        const form = this.formRef.props.form;
        form.validateFields((err, values) => {
            console.log(err);
            console.log(values);
            if (err) {
                return;
            }
            if (this.state.text == "土壤处理量统计表") {
                values.cldate = values.cldate.format("YYYY-MM-DD");
                values.takeTime = `${values.cldate}`;
            }

            if (this.state.text == "土壤修复指标汇总表") {
                values.startTime = values.startTime.format("YYYY-MM-DD");
                values.startTime1 = values.startTime1.format("HH:mm:ss");
                console.log(values.endTime);

                values.startTime = `${values.startTime} ${values.startTime1}`;
                if (values.endTime1 && values.endTime) {
                    values.endTime = `${values.endTime} ${values.endTime1}`;
                } else {
                    values.endTime = "";
                }
            }

            if (this.state.text == "能源消耗统计表") {
                values.nydata = values.nydata.format("YYYY-MM-DD");
                values.nytime = values.nytime.format("HH:00:00");
                values.takeTime = `${values.nydata} ${values.nytime}`;

                values.useElectric = parseFloat(values.useElectric);
                values.useNaturalGas = parseFloat(values.useNaturalGas);
                values.useWater = parseFloat(values.useWater);
            }

            delete values.date;
            delete values.time;

            //新增发请求

            if (this.state.text == "能源消耗统计表") {
                reportformsadd({ ...values }).then(data => {
                    console.log(data);
                    if (data.data.rc == 0) {
                        let data = {
                            page: 1,
                            rows: 10
                        };
                        reportformsinquire({ ...data }).then(data => {
                            console.log(data);
                            data.data.ret.items.forEach(item => {
                                item.takeTime2 = moment(item.takeTime).format(
                                    "YYYY-MM-DD"
                                );
                                item.takeTime1 = moment(item.takeTime).format(
                                    "HH:00"
                                );
                            });
                            this.setState({
                                data: data.data.ret.items
                            });
                        });
                    }
                });
            }

            if (this.state.text == "土壤处理量统计表") {
                //   values.times = values.time
                console.log(values);
                disposeAdd({ ...values }).then(data => {
                    console.log(data);
                    if (data.data.rc == 0) {
                        let data = {
                            page: this.state.page,
                            rows: this.state.rows,
                            endDateStr: this.state.endDate,
                            startDateStr: this.state.startDate
                        };
                        disposeQuery({ ...data }).then(data => {
                            console.log(data);
                            data.data.ret.items.forEach(item => {
                                item.takeTime = moment(item.takeTime).format(
                                    "YYYY-MM-DD"
                                );
                            });
                            this.setState({
                                data: data.data.ret.items
                            });
                        });
                    }
                });
            }

            if (this.state.text == "土壤修复指标汇总表") {
                console.log(values);
                //   values.times = values.time
                repairAdd({ ...values }).then(data => {
                    if (data.data.rc == 0) {
                        let data = {
                            page: this.state.page,
                            rows: this.state.rows,
                            endDateStr: this.state.endDate,
                            startDateStr: this.state.startDate
                        };
                        repairQuery({ ...data }).then(data => {
                            console.log(data);
                            if (data.data.rc == 0) {
                                data.data.ret.items.forEach(item => {
                                    item.startTime = moment(
                                        item.startTime
                                    ).format("YYYY-MM-DD");
                                    if (item.endTime == null) {
                                        item.endTime = "";
                                    } else {
                                        item.endTime = moment(
                                            item.endTime
                                        ).format("YYYY-MM-DD");
                                    }
                                });
                            }

                            this.setState({
                                data: data.data.ret.items
                            });
                        });
                    }
                });
            }

            console.log(values);
            form.resetFields();
            this.setState({ visible: false, visible1: false, visible2: false });
        });
    };
    saveFormRef = formRef => {
        this.formRef = formRef;
    };
    //初始表格值

    //删除按钮
    btnDelete = () => {
        var arr = [];
        if (this.state.row.length > 0) {
            this.state.row.forEach(item => {
                arr.push({
                    id: item.id
                });
            });
            //删除按钮弹框
            confirm({
                text: this.state.text,
                title: "删除数据?",
                content: "点击确定后,数据将不存在",
                cancelText: "取消",
                okText: "确定",
                onOk: () => {
                    if (this.state.text == "能源消耗统计表") {
                        statementDelete(arr).then(data => {
                            if (data.data.rc == 0) {
                                let data = {
                                    page: 1,
                                    rows: 10
                                };
                                reportformsinquire({ ...data }).then(data => {
                                    data.data.ret.items.forEach(item => {
                                        item.takeTime2 = moment(
                                            item.takeTime
                                        ).format("YYYY-MM-DD");
                                        item.takeTime1 = moment(
                                            item.takeTime
                                        ).format("HH:00");
                                    });
                                    this.setState({
                                        data: data.data.ret.items,
                                        selectedRowKeys: []
                                    });
                                });
                            }
                        });
                    }

                    if (this.state.text == "土壤处理量统计表") {
                        disposeDelete(arr).then(data => {
                            if (data.data.rc == 0) {
                                let data = {
                                    page: this.state.page,
                                    rows: this.state.rows,
                                    endDateStr: this.state.endDate,
                                    startDateStr: this.state.startDate
                                };
                                disposeQuery({ ...data }).then(data => {
                                    data.data.ret.items.forEach(item => {
                                        item.takeTime = moment(
                                            item.takeTime
                                        ).format("YYYY-MM-DD");
                                    });
                                    this.setState({
                                        data: data.data.ret.items,
                                        selectedRowKeys: []
                                    });
                                });
                            }
                        });
                    }

                    if (this.state.text == "土壤修复指标汇总表") {
                        repairDelete(arr).then(data => {
                            if (data.data.rc == 0) {
                                let data = {
                                    page: this.state.page,
                                    rows: this.state.rows,
                                    endDateStr: this.state.endDate,
                                    startDateStr: this.state.startDate
                                };
                                repairQuery({ ...data }).then(data => {
                                    if (data.data.rc == 0) {
                                        data.data.ret.items.forEach(item => {
                                            item.startTime = moment(
                                                item.startTime
                                            ).format("YYYY-MM-DD");
                                            if (item.endTime == null) {
                                                item.endTime = "";
                                            } else {
                                                item.endTime = moment(
                                                    item.endTime
                                                ).format("YYYY-MM-DD");
                                            }
                                        });
                                    }

                                    this.setState({
                                        data: data.data.ret.items,
                                        selectedRowKeys: []
                                    });
                                });
                            }
                        });
                    }
                },

                onCancel() {}
            });
        }

        console.log(arr);
    };
    //导出按钮
    derive = e => {
        if (this.state.text == "能源消耗统计表") {
            if (e.key == "item_0") {
                //导出本页
                let data = {
                    page: 1,
                    rows: 10,
                    isAll: false
                };
                window.location.href = `/hh-management-web/gnhj/energyconsumption/energyConsumptionExcelExport?page=${
                    data.page
                }&rows=${data.rows}&isAll=${data.isAll}&endDateStr=${
                    this.state.endDate
                }&startDateStr=${this.state.startDate}`;
            } else {
                //导出全部
                let data = {
                    page: 1,
                    rows: 10,
                    isAll: false
                };
                window.location.href = `/hh-management-web/gnhj/energyconsumption/energyConsumptionExcelExport?page=${
                    data.page
                }&rows=${data.rows}&isAll=${true}&endDateStr=${
                    this.state.endDate
                }&startDateStr=${this.state.startDate}`;
            }
        }

        if (this.state.text == "土壤处理量统计表") {
            if (e.key == "item_0") {
                //导出本页
                let data = {
                    page: 1,
                    rows: 10,
                    isAll: false
                };
                window.location.href = `/hh-management-web/gnhj/soilTreatment/soilTreatmentExcelExport?page=${
                    data.page
                }&rows=${data.rows}&isAll=${data.isAll}&endDateStr=${
                    this.state.endDate
                }&startDateStr=${this.state.startDate}`;
            } else {
                //导出全部
                let data = {
                    page: 1,
                    rows: 10,
                    isAll: false
                };
                window.location.href = `/hh-management-web/gnhj/soilTreatment/soilTreatmentExcelExport?page=${
                    data.page
                }&rows=${data.rows}&isAll=${true}&endDateStr=${
                    this.state.endDate
                }&startDateStr=${this.state.startDate}`;
            }
        }

        if (this.state.text == "土壤修复指标汇总表") {
            if (e.key == "item_0") {
                //导出本页
                let data = {
                    page: 1,
                    rows: 10,
                    isAll: false
                };
                window.location.href = `/hh-management-web/gnhj/soilremediation/soilRemediationExcelExport?page=${
                    data.page
                }&rows=${data.rows}&isAll=${data.isAll}&endDateStr=${
                    this.state.endDate
                }&startDateStr=${this.state.startDate}`;
            } else {
                //导出全部
                let data = {
                    page: 1,
                    rows: 10,
                    isAll: false
                };
                window.location.href = `/hh-management-web/gnhj/soilremediation/soilRemediationExcelExport?page=${
                    data.page
                }&rows=${data.rows}&isAll=${true}&endDateStr=${
                    this.state.endDate
                }&startDateStr=${this.state.startDate}`;
            }
        }
    };

    rowSelection = e => {
        console.log(e);
    };
    onShowSizeChange = (page, rows) => {
        console.log(page, rows);
        this.setState({
            pg: page,
            page: page,
            rows: rows
        });
        setTimeout(() => {
            this.save();
        });
    };

    //分页器分页事件
    Pagination = (page, pageSize) => {
        console.log(page, pageSize);
        this.setState({
            pg: page,
            page: page,
            rows: pageSize
        });

        setTimeout(() => {
            this.save();
        });
    };

    //重置表格事件

    reset = () => {
        this.setState({
            tableLoading: true,
            RangePicker: null,
            endDate: "",
            startDate: "",
            page: 1,
            text1: "能源消耗统计表",
            data: []
        });

        setTimeout(() => {
            //发分页查询请求
            let data = {
                page: 1,
                rows: 10,
                endDateStr: "",
                startDateStr: ""
            };
            reportformsinquire({ ...data }).then(data => {
                console.log(data);
                data.data.ret.items.forEach(item => {
                    item.takeTime2 = moment(item.takeTime).format("YYYY-MM-DD");
                    item.takeTime1 = moment(item.takeTime).format("HH:00");
                });
                this.setState({
                    data: data.data.ret.items,
                    repairWidth: null,
                    tableLoading: false,
                    rowCount: data.data.ret.rowCount
                });
            });

            this.setState({
                columns: [
                    {
                        title: "序号",
                        dataIndex: "num",
                        key: "num",
                        align: "center"
                    },
                    {
                        title: "日期",
                        dataIndex: "takeTime2",
                        key: "takeTime2",
                        align: "center"
                    },
                    {
                        title: "时间",
                        dataIndex: "takeTime1",
                        key: "takeTime1",
                        align: "center"
                    },
                    {
                        title: "燃气抄表值/Nm3",
                        key: "useNaturalGas",
                        dataIndex: "useNaturalGas",
                        align: "center"
                    },
                    {
                        title: "电耗抄表值/kWh",
                        key: "useElectric",
                        dataIndex: "useElectric",
                        align: "center"
                    },
                    {
                        title: "水耗抄表值/t",
                        key: "useWater",
                        dataIndex: "useWater",
                        align: "center"
                    },
                    {
                        title: "记录人",
                        key: "opertion",
                        dataIndex: "opertion",
                        align: "center"
                    },
                    {
                        title: "备注",
                        key: "remarkText",
                        dataIndex: "remarkText",
                        align: "center"
                    }
                ]
            });
        }, 300);
    };

    componentWillMount() {
        //判断是否是驾驶舱跳转来的

        //进入页面发出分页查询请求
        let data = {
            page: 1,
            rows: 10,
            endDateStr: this.state.endDate,
            startDateStr: this.state.startDate
        };
        reportformsinquire({ ...data }).then(data => {
            if (data.data.rc == 0) {
                data.data.ret.items.forEach(item => {
                    item.takeTime2 = moment(item.takeTime).format("YYYY-MM-DD");
                    item.takeTime1 = moment(item.takeTime).format("HH:00");
                });
            }

            this.setState({
                data: data.data.ret.items,
                rowCount: data.data.ret.rowCount,
                columns: [
                    {
                        title: "序号",
                        dataIndex: "num",
                        key: "num",
                        align: "center"
                    },
                    {
                        title: "日期",
                        dataIndex: "takeTime2",
                        key: "takeTime2",
                        align: "center"
                    },
                    {
                        title: "时间",
                        dataIndex: "takeTime1",
                        key: "takeTime1",
                        align: "center"
                    },
                    {
                        title: "燃气抄表值/Nm3",
                        key: "useNaturalGas",
                        dataIndex: "useNaturalGas",
                        align: "center"
                    },
                    {
                        title: "电耗抄表值/kWh",
                        key: "useElectric",
                        dataIndex: "useElectric",
                        align: "center"
                    },
                    {
                        title: "水耗抄表值/t",
                        key: "useWater",
                        dataIndex: "useWater",
                        align: "center"
                    },
                    {
                        title: "记录人",
                        key: "opertion",
                        dataIndex: "opertion",
                        align: "center"
                    },
                    {
                        title: "备注",
                        key: "remarkText",
                        dataIndex: "remarkText",
                        align: "center"
                    }
                ]
            });
        });

        this.handleChange = e => {
            this.setState({
                text: e,
                row: {},
                text1: e
            });
        };
        //点击查询更换不同表格
        this.save = () => {
            this.setState({
                tableLoading: true,
                data: [],
                columns: []
            });
            //土壤修复指标汇总表
            if (this.state.text == "土壤修复指标汇总表") {
                let data = {
                    page: this.state.page,
                    rows: this.state.rows,
                    endDateStr: this.state.endDate,
                    startDateStr: this.state.startDate
                };
                repairQuery({ ...data }).then(data => {
                    console.log(data);
                    if (data.data.rc == 0) {
                        data.data.ret.items.forEach(item => {
                            item.startTime = moment(item.startTime).format(
                                "YYYY-MM-DD"
                            );
                            if (item.endTime == null) {
                                item.endTime = "";
                            } else {
                                item.endTime = moment(item.endTime).format(
                                    "YYYY-MM-DD"
                                );
                            }
                        });
                    }

                    setTimeout(() => {
                        this.setState({
                            data: data.data.ret.items,
                            repairWidth: 2000,

                            rowCount: data.data.ret.rowCount,
                            tableLoading: false,
                            columns: [
                                {
                                    title: "批次",
                                    dataIndex: "batches",
                                    key: "batches",
                                    align: "center",
                                    width: 170
                                },
                                {
                                    title: "开始时间",
                                    dataIndex: "startTime",
                                    key: "startTime",
                                    align: "center",
                                    width: 170
                                },
                                {
                                    title: "结束时间",
                                    dataIndex: "endTime",
                                    key: "endTime",
                                    align: "center",
                                    width: 170
                                },
                                {
                                    title: "处理时间",
                                    key: "processingTime",
                                    dataIndex: "processingTime",
                                    align: "center",
                                    width: 170
                                },
                                {
                                    title: "处理量/t",
                                    key: "throughput",
                                    dataIndex: "throughput",
                                    align: "center",
                                    width: 80
                                },
                                {
                                    title: "处理温度均值/℃",
                                    key: "processingTemperature",
                                    dataIndex: "processingTemperature",
                                    align: "center",
                                    width: 170
                                },
                                {
                                    title: "停留时间/min",
                                    key: "waitTime",
                                    dataIndex: "waitTime",
                                    align: "center",
                                    width: 100
                                },
                                {
                                    title: "六氯苯",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing1",
                                            key: "beforeProcessing1",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing1",
                                            key: "afterProcessing1",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "硝基苯",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing2",
                                            key: "beforeProcessing2",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing2",
                                            key: "afterProcessing2",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "苯并(a)芘",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing3",
                                            key: "beforeProcessing3",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing3",
                                            key: "afterProcessing3",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "苯并(a)蒽",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing4",
                                            key: "beforeProcessing4",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing4",
                                            key: "afterProcessing4",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "三氯乙烯",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing5",
                                            key: "beforeProcessing5",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing5",
                                            key: "afterProcessing5",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "1,4-二氯苯",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing6",
                                            key: "beforeProcessing6",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing6",
                                            key: "afterProcessing6",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "污染物质7",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing7",
                                            key: "beforeProcessing7",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing7",
                                            key: "afterProcessing7",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "污染物质8",
                                    align: "center",
                                    children: [
                                        {
                                            title: "处理前",
                                            dataIndex: "beforeProcessing8",
                                            key: "beforeProcessing8",
                                            width: 80
                                        },
                                        {
                                            title: "处理后",
                                            dataIndex: "afterProcessing8",
                                            key: "afterProcessing8",
                                            width: 80
                                        }
                                    ]
                                },
                                {
                                    title: "备注",
                                    key: "remarkText",
                                    dataIndex: "remarkText",
                                    align: "center",
                                    width: 150
                                }
                            ]
                        });
                    }, 500);
                });
            }
            if (this.state.text == "土壤处理量统计表") {
                //土壤处理量统计表
                let data = {
                    page: this.state.page,
                    rows: this.state.rows,
                    endDateStr: this.state.endDate,
                    startDateStr: this.state.startDate
                };
                disposeQuery({ ...data }).then(data => {
                    console.log(data);
                    data.data.ret.items.forEach(item => {
                        item.takeTime = moment(item.takeTime).format(
                            "YYYY-MM-DD"
                        );
                    });
                    setTimeout(() => {
                        this.setState({
                            data: data.data.ret.items,
                            repairWidth: null,
                            rowCount: data.data.ret.rowCount,
                            tableLoading: false,
                            columns: [
                                {
                                    title: "序号",
                                    dataIndex: "num",
                                    key: "num",
                                    align: "center"
                                },
                                {
                                    title: "日期",
                                    dataIndex: "takeTime",
                                    key: "takeTime",
                                    align: "center"
                                },
                                {
                                    title: "时间",
                                    dataIndex: "times",
                                    key: "times",
                                    align: "center"
                                },
                                {
                                    title: "班组",
                                    key: "banzu",
                                    dataIndex: "banzu",
                                    align: "center"
                                },
                                {
                                    title: "土壤处理量/t",
                                    key: "throughput",
                                    dataIndex: "throughput",
                                    align: "center"
                                },
                                {
                                    title: "记录人",
                                    key: "opertion",
                                    dataIndex: "opertion",
                                    align: "center"
                                },
                                {
                                    title: "备注",
                                    key: "remarkText",
                                    dataIndex: "remarkText",
                                    align: "center"
                                }
                            ]
                        });
                    }, 500);
                });
            }
            if (this.state.text == "能源消耗统计表") {
                //发分页查询请求
                let data = {
                    page: this.state.page,
                    rows: this.state.rows,
                    endDateStr: this.state.endDate,
                    startDateStr: this.state.startDate
                };
                reportformsinquire({ ...data }).then(data => {
                    console.log(data);
                    data.data.ret.items.forEach(item => {
                        item.takeTime2 = moment(item.takeTime).format(
                            "YYYY-MM-DD"
                        );
                        item.takeTime1 = moment(item.takeTime).format("HH:00");
                    });
                    setTimeout(() => {
                        this.setState({
                            data: data.data.ret.items,
                            repairWidth: null,
                            rowCount: data.data.ret.rowCount,
                            tableLoading: false,
                            columns: [
                                {
                                    title: "序号",
                                    dataIndex: "num",
                                    key: "num",
                                    align: "center"
                                },
                                {
                                    title: "日期",
                                    dataIndex: "takeTime2",
                                    key: "takeTime2",
                                    align: "center"
                                },
                                {
                                    title: "时间",
                                    dataIndex: "takeTime1",
                                    key: "takeTime1",
                                    align: "center"
                                },
                                {
                                    title: "燃气抄表值/Nm3",
                                    key: "useNaturalGas",
                                    dataIndex: "useNaturalGas",
                                    align: "center"
                                },
                                {
                                    title: "电耗抄表值/kWh",
                                    key: "useElectric",
                                    dataIndex: "useElectric",
                                    align: "center"
                                },
                                {
                                    title: "水耗抄表值/t",
                                    key: "useWater",
                                    dataIndex: "useWater",
                                    align: "center"
                                },
                                {
                                    title: "记录人",
                                    key: "opertion",
                                    dataIndex: "opertion",
                                    align: "center"
                                },
                                {
                                    title: "备注",
                                    key: "remarkText",
                                    dataIndex: "remarkText",
                                    align: "center"
                                }
                            ]
                        });
                    }, 500);
                });
            }
        };
        //点击新增事件
    }

    //编辑成功后的回调
    editcg(a) {
        console.log(this);

        if (a == "1") {
            this.save();
            this.setState({
                visible1: false
            });
        }
    }
    //多选
    onSelectChange = (selectedRowKeys, row) => {
        this.setState({
            row: row,
            selectedRowKeys
        });
    };

    render() {
        console.log(this.props.location);
        const menu = (
            <Menu>
                <Menu.Item onClick={this.derive}>本页</Menu.Item>
                <Menu.Item onClick={this.derive}>全部</Menu.Item>
            </Menu>
        );
        const {
            visible,
            visible1,
            visible2,
            loading,
            btn,
            selectedRowKeys
        } = this.state;

        //     const rowSelection = {
        //       onChange: (selectedRowKeys, selectedRows) => {

        //           console.log(
        //               `selectedRowKeys: ${selectedRowKeys}`,
        //               "selectedRows: ",
        //               selectedRows
        //           );
        //           setTimeout(() => {

        //             rowSelection.selectedRowKeys=""
        //             console.log(`selectedRowKeys: ${selectedRowKeys}`)
        //           },2000)

        //           this.setState({
        //             row:selectedRows
        //           })

        //       },
        //       getCheckboxProps: record => ({
        //           disabled: record.name === "Disabled User", // Column configuration not to be checked
        //           name: record.name
        //       })
        //   };

        let rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange.bind(this)
        };

        console.log(this.state.row);
        return (
            <div>
                <CollectionCreateForm
                    wrappedComponentRef={this.saveFormRef}
                    visible={this.state.visible}
                    onCancel={this.handleCancel}
                    onCreate={this.handleCreate}
                    text={this.state.text}
                    btn={this.state.btn}
                />
                <Editmodal
                    visible1={this.state.visible1}
                    onCancel={this.handleCancel}
                    text={this.state.text}
                    row={this.state.row1}
                    editState={this.state.editState}
                    editcg={this.editcg.bind(this)}
                />
                <Checkmodal
                    visible2={this.state.visible2}
                    onCancel={this.handleCancel}
                    text={this.state.text}
                    row={this.state.row1}
                />
                <Card className={style.CardTop}>
                    <div className={style.Top}>
                        报表名称:
                        <Select
                            defaultValue="能源消耗统计表"
                            style={{ width: 240 }}
                            onChange={this.handleChange}
                            className={style.MonthPicker}
                            ref="text"
                            value={this.state.text1}
                        >
                            <Option value="能源消耗统计表">
                                能源消耗统计表
                            </Option>
                            <Option value="土壤修复指标汇总表">
                                土壤修复指标汇总表
                            </Option>
                            <Option value="土壤处理量统计表">
                                土壤处理量统计表
                            </Option>
                        </Select>
                        查询时间:{" "}
                        <RangePicker
                            value={this.state.RangePicker}
                            allowClear={true}
                            onChange={this.RangePicker.bind(this.RangePicker)}
                            placeholder={["开始时间", "结束时间"]}
                        />
                        <Button
                            type="primary"
                            className={style.primary}
                            onClick={this.save}
                        >
                            查询
                        </Button>
                        <Button className={style.reset} onClick={this.reset}>
                            重置
                        </Button>
                    </div>
                </Card>
                <Card
                    className={style.CardBottom}
                    bodyStyle={{ paddingTop: "2vh" }}
                >
                    <div>
                        <span
                            className={style.click_span}
                            type="primary"
                            onClick={this.showModal}
                        >
                            <MyIcon
                                type="icon-xinzeng"
                                className={style.MyIcon_xinzeng}
                            />
                            新增
                        </span>
                        <Divider type="vertical" />
                        <span
                            className={style.click_span}
                            type="primary"
                            onClick={this.showModal2}
                        >
                            <MyIcon
                                type="icon-chakan1"
                                className={style.MyIcon_chakan1}
                            />
                            查看
                        </span>
                        <Divider type="vertical" />
                        <span
                            className={style.click_span}
                            type="primary"
                            onClick={this.showModal1}
                        >
                            <MyIcon
                                type="icon-gongneng"
                                className={style.MyIcon_gongneng}
                            />
                            编辑
                        </span>
                        <Divider type="vertical" />
                        <span className={style.click_span} type="primary">
                            <MyIcon
                                type="icon-webicon320"
                                className={style.MyIcon_webicon320}
                            />
                            <Dropdown overlay={menu}>
                                <span className="ant-dropdown-link">
                                    导出 <Icon type="down" />
                                </span>
                            </Dropdown>
                        </span>
                        <Divider type="vertical" />
                        <span
                            className={style.click_span}
                            type="primary"
                            //删除按钮事件
                            onClick={this.btnDelete}
                        >
                            <MyIcon
                                type="icon-del"
                                className={style.MyIcon_del}
                            />
                            删除
                        </span>
                        <div className={style.myTable}>
                            <Table
                                ref="table"
                                loading={this.state.tableLoading}
                                style={{
                                    width: this.state.repairWidth,
                                    margin: 0
                                }}
                                onChange={this.rowSelection}
                                rowSelection={rowSelection}
                                columns={this.state.columns}
                                dataSource={publicService.transformArrayData(
                                    this.state.data,
                                    true,
                                    true
                                )}
                                align="center"
                                className={style.Table}
                                bordered={true}
                                pagination={false}
                                size="small"
                            />
                        </div>
                        <Pagination
                            showSizeChanger
                            onShowSizeChange={this.onShowSizeChange}
                            showQuickJumper
                            defaultCurrent={1}
                            total={this.state.rowCount}
                            onChange={this.Pagination}
                            className={style.Pagination}
                            size="small"
                            current={this.state.page}
                        />
                    </div>
                </Card>
            </div>
        );
    }
}

export default connect()(Fill);
